<?php
class ModulesController extends AppController{
    var $name='Modules';
    var $mods=array(
        'User'=>array(
            'title'=>'addUser',
            'menutitle'=>'User',
            'get_action'=>'getUserDetails',
            'get_validation'=>'_validateUser'
        ),
        'New User'=>array(
            'title'=>'editNewUser',
            'menutitle'=>'New User',
            'get_action'=>'getUserDetails',
            'get_validation'=>'_validateUser'
        ),
        'Edit User'=>array(
            'title'=>'editUser',
            'menutitle'=>'Edit User',
            'get_action'=>'getUserDetails',
            'get_validation'=>'_validateUser'
        ),
        'Company'=>array(
            'title'=>'findCompany',
            'menutitle'=>'Company',
            'get_action'=>'getCompanyDetails',
            'get_validation'=>'_validateCompany'
        ),
        'Manager'=>array(
            'title'=>'addManager',
            'menutitle'=>'Manager',
            'get_action'=>'getManagerDetails',
            'get_validation'=>'_validateManager'
        ),
        'Manager Validation'=>array(
            'title'=>'managerValidation',
            'menutitle'=>'Manager Validation',
            'get_action'=>'getManagerValidationDetails'
        ),
        'Back Up'=>array(
            'title'=>'addBackup',
            'menutitle'=>'Back Up',
            'get_action'=>'getBackupDetails',
            'get_validation'=>'_validateBackup'
        ),
        'Jobs'=>array(
            'title'=>'editJob',
            'menutitle'=>'Jobs',
            'get_action'=>'getJobsDetails',
            'get_validation'=>'_validateJobs'
        ),
        'Branches'=>array(
            'title'=>'editBranch',
            'menutitle'=>'Branches/Cost centers',
            'get_action'=>'getBranchDetails',       
        ),
        'Workflows'=>array(
            'title'=>'editWorkflow',
            'menutitle'=>'Workflows',
            'get_action'=>''
        ),
        'PC'=>array(
            'title'=>'addPc',
            'menutitle'=>'PC',
            'get_action'=>'getPcDetails'
        ),
        'Tools'=>array(
            'title'=>'addTools',
            'menutitle'=>'Tools',
            'get_action'=>'getToolsDetails',
            'get_validation'=>'_validateTool'
        ),
        'Notes and Execution'=>array(
            'title'=>'addNotesAndExecutionDate',
            'menutitle'=>'Notes and Execution',
            'get_action'=>'getNotesAndExecution'
        ),
        
    );
        function  beforeFilter() {
            parent::beforeFilter();
            $this->Auth->autoRedirect = false;
            switch ($this->Auth->user('group_id')){
            case 1:$this->Auth->allow('*');break;
                case 2:$this->Auth->deny('*');$this->Auth->allow('*');break;
                case 3:$this->Auth->deny('*');$this->Auth->allow($this->eicoArray);break;
                case 4:$this->Auth->deny('*');$this->Auth->allow($this->toolAdminArray);break;
                case 5:$this->Auth->deny('*');$this->Auth->allow($this->demanderArray);break;
                case 7:$this->Auth->deny('*');$this->Auth->allow($this->basicUserArray);break;
                case 6:$this->Auth->deny('*');$this->Auth->allow($this->requesterArray);break;
            }
            $this->set('active',3);
        }
        
    function addModules(){
       $dmd=$this->Module->Dmdformtype->getTypes();
       $modules=array();
       foreach ($dmd as $did => $d){
           $modules[$d]=$this->Module->getModuleTitleNames($did);
       }
       $mods=  $this->mods;
       $this->set(compact('modules','dmd','mods'));
    }

    function listModules(){
       $dmd=$this->Module->Dmdformtype->getTypes();
       $modules=array();
       foreach ($dmd as $did => $d){
           $modules[$d]=$this->Module->getModules($did);
       }
       $this->set(compact('modules'));
    }
    function saveModules(){
        debug($this->data);
        if($this->data){
            $dmdId=$this->data['dmd']['nb'];
            $this->Module->deleteAll(array('dmdformtype_id'=>$dmdId),false);
            foreach($this->data['Module'] as $mKey => $m){
                $data=array();
                $data=array_merge($this->mods[$mKey],array('position'=>$m,'dmdformtype_id'=>$dmdId));
                $this->Module->create();
                $this->Module->save($data);
            }
        }
       
       
    }
}

?>
